<?php

namespace Admin\Models\pm;
use Helpers\Main;
use Phalcon\Mvc\Model;

class basicModel extends Model{


    public function beforeCreate()
    {

        $date=date('Y-m-d H:i:s', time());
        $id=Main::getLoginUserInfo('userId');
        $uname = Main::getLoginUserInfo('userName');

        if(property_exists($this, 'bDelete')){
            $this->writeAttribute('bDelete', 0);
        }

        if(property_exists($this,'tCreateDate')){
            $this->writeAttribute('tCreateDate', $date);
        }
        if(property_exists($this,'iCreateUserId')){
            $this->writeAttribute('iCreateUserId', $id);
        }
        if(property_exists($this,'sCreateUserName')){
            $this->writeAttribute('sCreateUserName', $uname);
        }
        if(property_exists($this,'tLastModifyDate')){
            $this->writeAttribute('tLastModifyDate', $date);
        }
        if(property_exists($this,'iLastModifyUserId')){
            $this->writeAttribute('iLastModifyUserId', $id);
        }
        if(property_exists($this,'sLastModifyUserName')){
            $this->writeAttribute('sLastModifyUserName', $uname);
        }
    }

    public function beforeUpdate()
    {
        $date = date('Y-m-d H:i:s', time());
        $id = Main::getLoginUserInfo('userId');
        $uname = Main::getLoginUserInfo('userName');
        if(property_exists($this,'sLastModifyUserName')){
            $this->writeAttribute('sLastModifyUserName', $uname);
        }
        if(property_exists($this,'tLastModifyDate')){
            $this->writeAttribute('tLastModifyDate', $date);
        }
        if(property_exists($this,'iLastModifyUserId')){
            $this->writeAttribute('iLastModifyUserId', $id);
        }
    }
    
}
